
import axios from './axios';
const getSelectOptionsList = async (url, queryParams= {}, fieldNames = {
  label: 'name',
  value: 'id',
  extraValue: '',
}, isPage = true) => {
  let currentOptions = [];
  let params = {
    ...queryParams
  }
  if(isPage) {
    params = {
      current: 1,
      size: -1,
      ...queryParams
    }
  }
  const res = await axios.get(url, { params });
  if(res) {
    let data = isPage ? res.content : res;
    currentOptions = data.map(item => ({
      label: item[fieldNames.label],
      value: item[fieldNames.value],
      extraValue: item[fieldNames.extraValue]
    }));
  }
  return currentOptions;
}

const getTreeOptionsList = async (url) => {
  let currentOptions = [];
  const res = await axios.get(url);
  if(res) {
    currentOptions = res;
  }
  return currentOptions;
}
export {
  getSelectOptionsList,
  getTreeOptionsList
} 